<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let obj = {
            name: "Hydra",
            age: 35,
        }

        // 解构赋值时，可以使用默认值，没有解构成功的时候，获取默认值。
        let {name,age = 18,sex = "男"} = obj;
        console.log("sex = ",sex); // 男
        console.log("age = ",age); // 35


        obj = {
            name: null,
            age: 35,
        }

        // 默认值，只能在解构的值是undefined时，才能使用到，解构的null值对于默认值不生效
        let arr = [null,1,undefined];
        let [a = "a",b = "b",c = "c",d = "d"] = arr;
        console.log("a = ",a); // null
        console.log("b = ",b); // 1
        console.log("c = ",c); // "c"
        console.log("d = ",d); // "d"

    </script>


</body>
</html>